package balance

import (
	"errors"
)

type RoundRobinBalance struct{
	Index int
}

func (b *RoundRobinBalance) DoBalance(objs []*Instance) (obj *Instance, err error) {
	if len(objs) == 0 {
		err = errors.New("没有传入任何实例")
		return
	}
	l := len(objs)
	if b.Index >= l {
		b.Index = 0
	}
	obj = objs[b.Index]
	b.Index = (b.Index + 1) % l
	return
}